home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / iceweasel / components / nsSafebrowsingApplication.js < prev    next >
Encoding:
Text File  |  2013-01-09  |  22.5 KB  |  673 lines

  1. const Cc = Components.classes;
  2. const Ci = Components.interfaces;
  3.  
  4. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  5.  
  6. // This is copied from toolkit/components/content/js/lang.js.
  7. // It seems cleaner to copy this rather than #include from so far away.
  8. Function.prototype.inherits = function(parentCtor) {
  9.   var tempCtor = function(){};
  10.   tempCtor.prototype = parentCtor.prototype;
  11.   this.superClass_ = parentCtor.prototype;
  12.   this.prototype = new tempCtor();
  13. }  
  14.  
  15. //@line 36 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/application.js"
  16.  
  17. // We instantiate this variable when we create the application.
  18. var gDataProvider = null;
  19.  
  20. // An instance of our application is a PROT_Application object. It
  21. // basically just populates a few globals and instantiates wardens,
  22. // the listmanager, and the about:blocked error page.
  23.  
  24. /**
  25.  * An instance of our application. There should be exactly one of these.
  26.  * 
  27.  * Note: This object should instantiated only at profile-after-change
  28.  * or later because the listmanager and the cryptokeymanager need to
  29.  * read and write data files. Additionally, NSS isn't loaded until
  30.  * some time around then (Moz bug #321024).
  31.  *
  32.  * @constructor
  33.  */
  34. function PROT_Application() {
  35.   this.debugZone= "application";
  36.  
  37. //@line 83 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/application.js"
  38.   
  39.   // expose some classes
  40.   this.PROT_PhishingWarden = PROT_PhishingWarden;
  41.   this.PROT_MalwareWarden = PROT_MalwareWarden;
  42.  
  43.   // Load data provider pref values
  44.   gDataProvider = new PROT_DataProvider();
  45.  
  46.   // expose the object
  47.   this.wrappedJSObject = this;
  48. }
  49.  
  50. var gInitialized = false;
  51. PROT_Application.prototype.initialize = function() {
  52.   if (gInitialized)
  53.     return;
  54.   gInitialized = true;
  55.  
  56.   var obs = Cc["@mozilla.org/observer-service;1"].
  57.             getService(Ci.nsIObserverService);
  58.   obs.addObserver(this, "xpcom-shutdown", true);
  59.  
  60.   // XXX: move table names to a pref that we originally will download
  61.   // from the provider (need to workout protocol details)
  62.   this.malwareWarden = new PROT_MalwareWarden();
  63.   this.malwareWarden.registerBlackTable("goog-malware-shavar");
  64.   this.malwareWarden.maybeToggleUpdateChecking();
  65.  
  66.   this.phishWarden = new PROT_PhishingWarden();
  67. //@line 115 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/application.js"
  68.   this.phishWarden.registerBlackTable("googpub-phish-shavar");
  69. //@line 117 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/application.js"
  70.   this.phishWarden.maybeToggleUpdateChecking();
  71. }
  72.  
  73. PROT_Application.prototype.observe = function(subject, topic, data) {
  74.   switch (topic) {
  75.     case "xpcom-shutdown":
  76.       this.malwareWarden.shutdown();
  77.       this.phishWarden.shutdown();
  78.       break;
  79.   }
  80. }
  81.  
  82. /**
  83.  * @param name String The type of url to get (either Phish or Error).
  84.  * @return String the report phishing URL (localized).
  85.  */
  86. PROT_Application.prototype.getReportURL = function(name) {
  87.   return gDataProvider["getReport" + name + "URL"]();
  88. }
  89.  
  90. PROT_Application.prototype.QueryInterface = function(iid) {
  91.   if (iid.equals(Ci.nsISupports) ||
  92.       iid.equals(Ci.nsISupportsWeakReference) ||
  93.       iid.equals(Ci.nsIObserver))
  94.     return this;
  95.  
  96.   throw Components.results.NS_ERROR_NO_INTERFACE;
  97. }
  98. //@line 37 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/globalstore.js"
  99.  
  100.  
  101. // A class that encapsulates data provider specific values.  The
  102. // root of the provider pref tree is browser.safebrowsing.provider.
  103. // followed by a number, followed by specific properties.  The properties
  104. // that a data provider can supply are:
  105. //
  106. // name: The name of the provider
  107. // keyURL: Before we send URLs in enhanced mode, we need to encrypt them
  108. // reportURL: When shown a warning bubble, we send back the user decision
  109. //            (get me out of here/ignore warning) to this URL (strip cookies
  110. //            first).  This is optional.
  111. // gethashURL: Url for requesting complete hashes from the provider.
  112. // reportGenericURL: HTML page for general user feedback
  113. // reportPhishURL: HTML page for notifying the provider of a new phishing page
  114. // reportErrorURL: HTML page for notifying the provider of a false positive
  115.  
  116. const kDataProviderIdPref = 'browser.safebrowsing.dataProvider';
  117. const kProviderBasePref = 'browser.safebrowsing.provider.';
  118.  
  119. //@line 60 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/globalstore.js"
  120. const MOZ_OFFICIAL_BUILD = false;
  121. //@line 62 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/globalstore.js"
  122.  
  123. const MOZ_PARAM_LOCALE = /\{moz:locale\}/g;
  124. const MOZ_PARAM_CLIENT = /\{moz:client\}/g;
  125. const MOZ_PARAM_BUILDID = /\{moz:buildid\}/g;
  126. const MOZ_PARAM_VERSION = /\{moz:version\}/g;
  127.  
  128. /**
  129.  * Information regarding the data provider.
  130.  */
  131. function PROT_DataProvider() {
  132.   this.prefs_ = new G_Preferences();
  133.  
  134.   this.loadDataProviderPrefs_();
  135.   
  136.   // Watch for changes in the data provider and update accordingly.
  137.   this.prefs_.addObserver(kDataProviderIdPref,
  138.                           BindToObject(this.loadDataProviderPrefs_, this));
  139.  
  140.   // Watch for when anti-phishing is toggled on or off.
  141.   this.prefs_.addObserver(kPhishWardenEnabledPref,
  142.                           BindToObject(this.loadDataProviderPrefs_, this));
  143. }
  144.  
  145. /**
  146.  * Populate all the provider variables.  We also call this when whenever
  147.  * the provider id changes.
  148.  */
  149. PROT_DataProvider.prototype.loadDataProviderPrefs_ = function() {
  150.   // Currently, there's no UI for changing local list provider so we
  151.   // hard code the value for provider 0.
  152.   this.updateURL_ = this.getUrlPref_(
  153.         'browser.safebrowsing.provider.0.updateURL');
  154.  
  155.   var id = this.prefs_.getPref(kDataProviderIdPref, null);
  156.  
  157.   // default to 0
  158.   if (null == id)
  159.     id = 0;
  160.   
  161.   var basePref = kProviderBasePref + id + '.';
  162.  
  163.   this.name_ = this.prefs_.getPref(basePref + "name", "");
  164.  
  165.   // Urls used to get data from a provider
  166.   this.keyURL_ = this.getUrlPref_(basePref + "keyURL");
  167.   this.reportURL_ = this.getUrlPref_(basePref + "reportURL");
  168.   this.gethashURL_ = this.getUrlPref_(basePref + "gethashURL");
  169.  
  170.   // Urls to HTML report pages
  171.   this.reportGenericURL_ = this.getUrlPref_(basePref + "reportGenericURL");
  172.   this.reportErrorURL_ = this.getUrlPref_(basePref + "reportErrorURL");
  173.   this.reportPhishURL_ = this.getUrlPref_(basePref + "reportPhishURL");
  174.   this.reportMalwareURL_ = this.getUrlPref_(basePref + "reportMalwareURL")
  175.   this.reportMalwareErrorURL_ = this.getUrlPref_(basePref + "reportMalwareErrorURL")
  176.  
  177.   // Propagate the changes to the list-manager.
  178.   this.updateListManager_();
  179. }
  180.  
  181. /**
  182.  * The list manager needs urls to operate.  It needs a url to know where the
  183.  * table updates are, and it needs a url for decrypting enchash style tables.
  184.  */
  185. PROT_DataProvider.prototype.updateListManager_ = function() {
  186.   var listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]
  187.                       .getService(Ci.nsIUrlListManager);
  188.  
  189.   // If we add support for changing local data providers, we need to add a
  190.   // pref observer that sets the update url accordingly.
  191.   listManager.setUpdateUrl(this.getUpdateURL());
  192.  
  193.   // setKeyUrl has the side effect of fetching a key from the server.
  194.   // This shouldn't happen if anti-phishing/anti-malware is disabled.
  195.   var isEnabled = this.prefs_.getPref(kPhishWardenEnabledPref, false) ||
  196.                   this.prefs_.getPref(kMalwareWardenEnabledPref, false);
  197.   if (isEnabled) {
  198.     listManager.setKeyUrl(this.keyURL_);
  199.   }
  200.  
  201.   listManager.setGethashUrl(this.getGethashURL());
  202. }
  203.  
  204. /**
  205.  * Lookup the value of a URL from prefs file and do parameter substitution.
  206.  */
  207. PROT_DataProvider.prototype.getUrlPref_ = function(prefName) {
  208.   var url = this.prefs_.getPref(prefName);
  209.  
  210.   var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
  211.                           .getService(Components.interfaces.nsIXULAppInfo);
  212.  
  213.   var mozClientStr = this.prefs_.getPref("browser.safebrowsing.clientid",
  214.                                          MOZ_OFFICIAL_BUILD ? 'navclient-auto-ffox' : appInfo.name);
  215.  
  216.   var versionStr = this.prefs_.getPref("browser.safebrowsing.clientver",
  217.                                        appInfo.version);
  218.  
  219.   // Parameter substitution
  220.   url = url.replace(MOZ_PARAM_LOCALE, this.getLocale_());
  221.   url = url.replace(MOZ_PARAM_CLIENT, mozClientStr);
  222.   url = url.replace(MOZ_PARAM_BUILDID, appInfo.appBuildID);
  223.   url = url.replace(MOZ_PARAM_VERSION, versionStr);
  224.   return url;
  225. }
  226.  
  227. /**
  228.  * @return String the browser locale (similar code is in nsSearchService.js)
  229.  */
  230. PROT_DataProvider.prototype.getLocale_ = function() {
  231.   const localePref = "general.useragent.locale";
  232.   var locale = this.getLocalizedPref_(localePref);
  233.   if (locale)
  234.     return locale;
  235.  
  236.   // Not localized
  237.   var prefs = new G_Preferences();
  238.   return prefs.getPref(localePref, "");
  239. }
  240.  
  241. /**
  242.  * @return String name of the localized pref, null if none exists.
  243.  */
  244. PROT_DataProvider.prototype.getLocalizedPref_ = function(aPrefName) {
  245.   // G_Preferences doesn't know about complex values, so we use the
  246.   // xpcom object directly.
  247.   var prefs = Cc["@mozilla.org/preferences-service;1"]
  248.               .getService(Ci.nsIPrefBranch);
  249.   try {
  250.     return prefs.getComplexValue(aPrefName, Ci.nsIPrefLocalizedString).data;
  251.   } catch (ex) {
  252.   }
  253.   return "";
  254. }
  255.  
  256. //////////////////////////////////////////////////////////////////////////////
  257. // Getters for the remote provider pref values mentioned above.
  258. PROT_DataProvider.prototype.getName = function() {
  259.   return this.name_;
  260. }
  261.  
  262. PROT_DataProvider.prototype.getUpdateURL = function() {
  263.   return this.updateURL_;
  264. }
  265.  
  266. PROT_DataProvider.prototype.getGethashURL = function() {
  267.   return this.gethashURL_;
  268. }
  269.  
  270. PROT_DataProvider.prototype.getReportGenericURL = function() {
  271.   return this.reportGenericURL_;
  272. }
  273. PROT_DataProvider.prototype.getReportErrorURL = function() {
  274.   return this.reportErrorURL_;
  275. }
  276. PROT_DataProvider.prototype.getReportPhishURL = function() {
  277.   return this.reportPhishURL_;
  278. }
  279. PROT_DataProvider.prototype.getReportMalwareURL = function() {
  280.   return this.reportMalwareURL_;
  281. }
  282. PROT_DataProvider.prototype.getReportMalwareErrorURL = function() {
  283.   return this.reportMalwareErrorURL_;
  284. }
  285. //@line 37 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/list-warden.js"
  286.  
  287. // A warden that knows how to register lists with a listmanager and keep them
  288. // updated if necessary.  The ListWarden also provides a simple interface to
  289. // check if a URL is evil or not.  Specialized wardens like the PhishingWarden
  290. // inherit from it.
  291. //
  292. // Classes that inherit from ListWarden are responsible for calling
  293. // enableTableUpdates or disableTableUpdates.  This usually entails
  294. // registering prefObservers and calling enable or disable in the base
  295. // class as appropriate.
  296. //
  297.  
  298. /**
  299.  * Abtracts the checking of user/browser actions for signs of
  300.  * phishing. 
  301.  *
  302.  * @constructor
  303.  */
  304. function PROT_ListWarden() {
  305.   this.debugZone = "listwarden";
  306.   var listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]
  307.                       .getService(Ci.nsIUrlListManager);
  308.   this.listManager_ = listManager;
  309.  
  310.   // Once we register tables, their respective names will be listed here.
  311.   this.blackTables_ = [];
  312.   this.whiteTables_ = [];
  313. }
  314.  
  315. PROT_ListWarden.IN_BLACKLIST = 0
  316. PROT_ListWarden.IN_WHITELIST = 1
  317. PROT_ListWarden.NOT_FOUND = 2
  318.  
  319. /**
  320.  * Tell the ListManger to keep all of our tables updated
  321.  */
  322.  
  323. PROT_ListWarden.prototype.enableBlacklistTableUpdates = function() {
  324.   for (var i = 0; i < this.blackTables_.length; ++i) {
  325.     this.listManager_.enableUpdate(this.blackTables_[i]);
  326.   }
  327. }
  328.  
  329. /**
  330.  * Tell the ListManager to stop updating our tables
  331.  */
  332.  
  333. PROT_ListWarden.prototype.disableBlacklistTableUpdates = function() {
  334.   for (var i = 0; i < this.blackTables_.length; ++i) {
  335.     this.listManager_.disableUpdate(this.blackTables_[i]);
  336.   }
  337. }
  338.  
  339. /**
  340.  * Tell the ListManager to update whitelist tables.  They may be enabled even
  341.  * when other updates aren't, for performance reasons.
  342.  */
  343. PROT_ListWarden.prototype.enableWhitelistTableUpdates = function() {
  344.   for (var i = 0; i < this.whiteTables_.length; ++i) {
  345.     this.listManager_.enableUpdate(this.whiteTables_[i]);
  346.   }
  347. }
  348.  
  349. /**
  350.  * Tell the ListManager to stop updating whitelist tables.
  351.  */
  352. PROT_ListWarden.prototype.disableWhitelistTableUpdates = function() {
  353.   for (var i = 0; i < this.whiteTables_.length; ++i) {
  354.     this.listManager_.disableUpdate(this.whiteTables_[i]);
  355.   }
  356. }
  357.  
  358. /**
  359.  * Register a new black list table with the list manager
  360.  * @param tableName - name of the table to register
  361.  * @returns true if the table could be registered, false otherwise
  362.  */
  363.  
  364. PROT_ListWarden.prototype.registerBlackTable = function(tableName) {
  365.   var result = this.listManager_.registerTable(tableName, false);
  366.   if (result) {
  367.     this.blackTables_.push(tableName);
  368.   }
  369.   return result;
  370. }
  371.  
  372. /**
  373.  * Register a new white list table with the list manager
  374.  * @param tableName - name of the table to register
  375.  * @returns true if the table could be registered, false otherwise
  376.  */
  377.  
  378. PROT_ListWarden.prototype.registerWhiteTable = function(tableName) {
  379.   var result = this.listManager_.registerTable(tableName, false);
  380.   if (result) {
  381.     this.whiteTables_.push(tableName);
  382.   }
  383.   return result;
  384. }
  385. //@line 36 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/phishing-warden.js"
  386.  
  387.  
  388. // The warden checks request to see if they are for phishy pages. It
  389. // does so by querying our locally stored blacklists.
  390. // 
  391. // When the warden notices a problem, it queries all browser views
  392. // (each of which corresopnds to an open browser window) to see
  393. // whether one of them can handle it. A browser view can handle a
  394. // problem if its browser window has an HTMLDocument loaded with the
  395. // given URL and that Document hasn't already been flagged as a
  396. // problem. For every problematic URL we notice loading, at most one
  397. // Document is flagged as problematic. Otherwise you can get into
  398. // trouble if multiple concurrent phishy pages load with the same URL.
  399. //
  400. // Since we check URLs very early in the request cycle (in a progress
  401. // listener), the URL might not yet be associated with a Document when
  402. // we determine that it is phishy. So the the warden retries finding
  403. // a browser view to handle the problem until one can, or until it
  404. // determines it should give up (see complicated logic below).
  405. //
  406. // The warden has displayers that the browser view uses to render
  407. // different kinds of warnings (e.g., one that's shown before a page
  408. // loads as opposed to one that's shown after the page has already
  409. // loaded).
  410. //
  411. // Note: There is a single warden for the whole application.
  412. //
  413. // TODO better way to expose displayers/views to browser view
  414.  
  415. const kPhishWardenEnabledPref = "browser.safebrowsing.enabled";
  416.  
  417. /**
  418.  * Abtracts the checking of user/browser actions for signs of
  419.  * phishing. 
  420.  *
  421.  * @param progressListener nsIDocNavStartProgressListener
  422.  * @param tabbrowser XUL tabbrowser element
  423.  * @constructor
  424.  */
  425. function PROT_PhishingWarden() {
  426.   PROT_ListWarden.call(this);
  427.  
  428.   this.debugZone = "phishwarden";
  429.  
  430.   // Use this to query preferences
  431.   this.prefs_ = new G_Preferences();
  432.  
  433.   // We need to know whether we're enabled and whether we're in advanced
  434.   // mode, so reflect the appropriate preferences into our state.
  435.  
  436.   // Global preference to enable the phishing warden
  437.   this.phishWardenEnabled_ = this.prefs_.getPref(kPhishWardenEnabledPref, null);
  438.  
  439.   // Get notifications when the phishing warden enabled pref changes
  440.   var phishWardenPrefObserver = 
  441.     BindToObject(this.onPhishWardenEnabledPrefChanged, this);
  442.   this.prefs_.addObserver(kPhishWardenEnabledPref, phishWardenPrefObserver);
  443.  
  444.   G_Debug(this, "phishWarden initialized");
  445. }
  446.  
  447. PROT_PhishingWarden.inherits(PROT_ListWarden);
  448.  
  449. PROT_PhishingWarden.prototype.QueryInterface = function(iid) {
  450.   if (iid.equals(Ci.nsISupports) || 
  451.       iid.equals(Ci.nsISupportsWeakReference))
  452.     return this;
  453.   throw Components.results.NS_ERROR_NO_INTERFACE;
  454. }
  455.  
  456. /**
  457.  * Cleanup on shutdown.
  458.  */
  459. PROT_PhishingWarden.prototype.shutdown = function() {
  460.   this.prefs_.removeAllObservers();
  461.   this.listManager_ = null;
  462. }
  463.  
  464. /**
  465.  * When a preference (either advanced features or the phishwarden
  466.  * enabled) changes, we might have to start or stop asking for updates. 
  467.  * 
  468.  * This is a little tricky; we start or stop management only when we
  469.  * have complete information we can use to determine whether we
  470.  * should.  It could be the case that one pref or the other isn't set
  471.  * yet (e.g., they haven't opted in/out of advanced features). So do
  472.  * nothing unless we have both pref values -- we get notifications for
  473.  * both, so eventually we will start correctly.
  474.  */ 
  475. PROT_PhishingWarden.prototype.maybeToggleUpdateChecking = function() {
  476.   var phishWardenEnabled = this.prefs_.getPref(kPhishWardenEnabledPref, null);
  477.  
  478.   G_Debug(this, "Maybe toggling update checking. " +
  479.           "Warden enabled? " + phishWardenEnabled);
  480.  
  481.   // Do nothing unless both prefs are set.  They can be null (unset), true, or
  482.   // false.
  483.   if (phishWardenEnabled === null)
  484.     return;
  485.  
  486.   // We update and save to disk all tables
  487.   if (phishWardenEnabled === true) {
  488.     this.enableBlacklistTableUpdates();
  489.     this.enableWhitelistTableUpdates();
  490.   } else {
  491.     // Anti-phishing is off, disable table updates
  492.     this.disableBlacklistTableUpdates();
  493.     this.disableWhitelistTableUpdates();
  494.   }
  495. }
  496.  
  497. /**
  498.  * Deal with a user changing the pref that says whether we should 
  499.  * enable the phishing warden (i.e., that SafeBrowsing is active)
  500.  *
  501.  * @param prefName Name of the pref holding the value indicating whether
  502.  *                 we should enable the phishing warden
  503.  */
  504. PROT_PhishingWarden.prototype.onPhishWardenEnabledPrefChanged = function(
  505.                                                                     prefName) {
  506.   // Just to be safe, ignore changes to sub prefs.
  507.   if (prefName != "browser.safebrowsing.enabled")
  508.     return;
  509.  
  510.   this.phishWardenEnabled_ = 
  511.     this.prefs_.getPref(prefName, this.phishWardenEnabled_);
  512.   this.maybeToggleUpdateChecking();
  513. }
  514. //@line 37 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/content/malware-warden.js"
  515.  
  516. // This warden manages updates to the malware list
  517.  
  518. const kMalwareWardenEnabledPref = "browser.safebrowsing.malware.enabled";
  519.  
  520. function PROT_MalwareWarden() {
  521.   PROT_ListWarden.call(this);
  522.  
  523.   this.debugZone = "malwarewarden";
  524.  
  525.   // Use this to query preferences
  526.   this.prefs_ = new G_Preferences();
  527.  
  528.   // Global preference to enable the malware warden
  529.   this.malwareWardenEnabled_ =
  530.     this.prefs_.getPref(kMalwareWardenEnabledPref, null);
  531.  
  532.   // Get notifications when the malware warden enabled pref changes
  533.   var malwareWardenPrefObserver =
  534.     BindToObject(this.onMalwareWardenEnabledPrefChanged, this);
  535.   this.prefs_.addObserver(kMalwareWardenEnabledPref, malwareWardenPrefObserver);
  536.  
  537.   // Add a test chunk to the database
  538.   var testData = "mozilla.org/firefox/its-an-attack.html";
  539.  
  540.   var testUpdate =
  541.     "n:1000\ni:test-malware-simple\nad:1\n" +
  542.     "a:1:32:" + testData.length + "\n" +
  543.     testData;
  544.     
  545.   testData = "mozilla.org/firefox/its-a-trap.html";
  546.   testUpdate +=
  547.     "n:1000\ni:test-phish-simple\nad:1\n" +
  548.     "a:1:32:" + testData.length + "\n" +
  549.     testData;
  550.  
  551.   var dbService_ = Cc["@mozilla.org/url-classifier/dbservice;1"]
  552.                    .getService(Ci.nsIUrlClassifierDBService);
  553.  
  554.   var listener = {
  555.     QueryInterface: function(iid)
  556.     {
  557.       if (iid.equals(Ci.nsISupports) ||
  558.           iid.equals(Ci.nsIUrlClassifierUpdateObserver))
  559.         return this;
  560.       throw Cr.NS_ERROR_NO_INTERFACE;
  561.     },
  562.  
  563.     updateUrlRequested: function(url) { },
  564.     streamFinished: function(status) { },
  565.     updateError: function(errorCode) { },
  566.     updateSuccess: function(requestedTimeout) { }
  567.   };
  568.  
  569.   try {
  570.     dbService_.beginUpdate(listener,
  571.                            "test-malware-simple,test-phish-simple", "");
  572.     dbService_.beginStream("", "");
  573.     dbService_.updateStream(testUpdate);
  574.     dbService_.finishStream();
  575.     dbService_.finishUpdate();
  576.   } catch(ex) {
  577.     // beginUpdate will throw harmlessly if there's an existing update
  578.     // in progress, ignore failures.
  579.   }
  580.   G_Debug(this, "malwareWarden initialized");
  581. }
  582.  
  583. PROT_MalwareWarden.inherits(PROT_ListWarden);
  584.  
  585. /**
  586.  * Cleanup on shutdown.
  587.  */
  588. PROT_MalwareWarden.prototype.shutdown = function() {
  589.   this.prefs_.removeAllObservers();
  590.  
  591.   this.listManager_ = null;
  592. }
  593.  
  594. /**
  595.  * When a preference changes, we might have to start or stop asking for
  596.  * updates.
  597.  */
  598. PROT_MalwareWarden.prototype.maybeToggleUpdateChecking = function() {
  599.   var malwareWardenEnabled = this.prefs_.getPref(kMalwareWardenEnabledPref,
  600.                                                  null);
  601.  
  602.   G_Debug(this, "Maybe toggling update checking. " +
  603.           "Warden enabled? " + malwareWardenEnabled);
  604.  
  605.   // Do nothing unless thre pref is set
  606.   if (malwareWardenEnabled === null)
  607.     return;
  608.  
  609.   // We update and save to disk all tables
  610.   if (malwareWardenEnabled === true) {
  611.     this.enableBlacklistTableUpdates();
  612.   } else {
  613.     // Anti-malware is off, disable table updates
  614.     this.disableBlacklistTableUpdates();
  615.   }
  616. }
  617.  
  618. /**
  619.  * Deal with a user changing the pref that says whether we should 
  620.  * enable the malware warden.
  621.  *
  622.  * @param prefName Name of the pref holding the value indicating whether
  623.  *                 we should enable the malware warden
  624.  */
  625. PROT_MalwareWarden.prototype.onMalwareWardenEnabledPrefChanged = function(
  626.                                                                     prefName) {
  627.   // Just to be safe, ignore changes to sub prefs.
  628.   if (prefName != kMalwareWardenEnabledPref)
  629.     return;
  630.  
  631.   this.malwareWardenEnabled_ =
  632.     this.prefs_.getPref(prefName, this.malwareWardenEnabled_);
  633.   this.maybeToggleUpdateChecking();
  634. }
  635. //@line 20 "/tmp/buildd/iceweasel-10.0.12esr/browser/components/safebrowsing/src/nsSafebrowsingApplication.js"
  636.  
  637. var modScope = this;
  638. function Init() {
  639.   var jslib = Cc["@mozilla.org/url-classifier/jslib;1"]
  640.               .getService().wrappedJSObject;
  641.   modScope.G_Debug = jslib.G_Debug;
  642.   modScope.G_Assert = jslib.G_Assert;
  643.   modScope.G_Alarm = jslib.G_Alarm;
  644.   modScope.G_ConditionalAlarm = jslib.G_ConditionalAlarm;
  645.   modScope.G_ObserverWrapper = jslib.G_ObserverWrapper;
  646.   modScope.G_Preferences = jslib.G_Preferences;
  647.   modScope.PROT_XMLFetcher = jslib.PROT_XMLFetcher;
  648.   modScope.BindToObject = jslib.BindToObject;
  649.   modScope.G_Protocol4Parser = jslib.G_Protocol4Parser;
  650.   modScope.PROT_UrlCrypto = jslib.PROT_UrlCrypto;
  651.   modScope.RequestBackoff = jslib.RequestBackoff;
  652.   
  653.   // We only need to call Init once
  654.   modScope.Init = function() {};
  655. }
  656.  
  657. function SafeBrowsingApplication()
  658. {
  659. }
  660. SafeBrowsingApplication.prototype = {
  661.   classID: Components.ID("{c64d0bcb-8270-4ca7-a0b3-3380c8ffecb5}"),
  662.   _xpcom_factory: {
  663.     createInstance: function(outer, iid) {
  664.       if (outer != null)
  665.         throw Components.results.NS_ERROR_NO_AGGREGATION;
  666.       Init();
  667.       return new PROT_Application();
  668.     }
  669.   },
  670. };
  671.  
  672. var NSGetFactory = XPCOMUtils.generateNSGetFactory([SafeBrowsingApplication]);
  673.